home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char rcsid[] = "$Header: review.c,v 1.4 87/05/19 18:45:56 schoch Exp $";
- #endif
-
- #include "externs.h"
- #include <sys/time.h>
- #define STEPTIME 3 /* time between moves in seconds */
-
- /*
- * Show a review of the game, with all pieces showing. I assume this doesn't
- * get called when we're playing.
- */
- review ()
- {
- int color = WHITE;
- MOVELIST m;
- auto int fds;
- struct timeval tv;
-
- if (state == REVIEW) {
- message("Already showing review\n", MESSAGE);
- return;
- }
- state = REVIEW;
- initdirlists ();
- initpiecelocs ();
- initboard (TRUE);
- #ifndef XKS
- touchwin (stdscr);
- #endif
- redraw ();
- m = movelist;
- while (m) {
- if (state != REVIEW) /* somebody stopped us. */
- return;
- #ifdef XKS
- fds = 1 << dpyno();
- #else
- fds = 1; /* stdin */
- #endif
- tv.tv_usec = 0;
- tv.tv_sec = STEPTIME;
- (void) select(32, &fds, 0, 0, &tv);
- #ifdef XKS
- if (fds & (1<<dpyno())) {
- handle_input();
- if (state != REVIEW)
- return;
- while (XPending()) {
- handle_input();
- if (state != REVIEW)
- return;
- }
- continue;
- }
- #else
- if (fds & 1) {
- if (getchar() == '\f') /* control-L */
- redraw();
- continue;
- }
- #endif
- if (occupant[m->from] == KING &&
- ((m->to - m->from) == 2 ||
- (m->from - m->to) == 2)) { /* castling */
- makereviewmove (m -> from, m -> to, color);
- m = m->n;
- }
- makereviewmove (m -> from, m -> to, color);
- refresh();
- m = m -> n;
- color = 1 - color;
- }
- state = OVER;
- }
-
- makereviewmove (from, to, color)
- int from, to, color;
- {
- int victim;
- char buf[128];
-
- mclear(INPUT);
- if (victim = findvictim (from, to)) {
- display_capture(whose[victim], occupant[victim]);
- whose [victim] = EMPTY;
- occupant[victim] = 0;
- redraw_pos(victim);
- }
- whose [to] = color;
- occupant [to] = occupant [from];
- whose [from] = EMPTY;
- occupant [from] = 0;
- if (occupant [to] == PAWN
- && ((to / 10 == 1 && color == WHITE)
- || (to / 10 == 8 && color == BLACK)))
- occupant [to] = QUEEN;
- redraw_pos(from);
- redraw_piece(to);
- if (reverse) {
- from = 99 - from;
- to = 99 - to;
- }
- sprintf(buf, ": %1c%1d-%1c%1d", 'a' + (9-from%10)-1, (9-from/10),
- 'a' + (9 - to%10)-1, (9 - to/10));
- message(buf, INPUT);
- }
-